package pl.diagnoser.server.persistance.map;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import pl.diagnoser.client.dto.DefectDictDTO;

@Entity
@Table(name = "D_DEFECT")
public class DefectDict implements Serializable, Comparable<DefectDict> {

        private static final long serialVersionUID = 3888940678316286508L;
        private String defectName;
        private double defectConfidence = 0.0;
        
        public DefectDict() {}
        public DefectDict( String illnessName ) {
                this.defectName = illnessName;
        }
        public DefectDict( String illnessName, double illnessConfidence ) {
                this.defectName = illnessName;
                this.defectConfidence = illnessConfidence;
        }
        
        public DefectDict( DefectDictDTO defectDict ) {
                this.defectName = defectDict.getDefectName();
                this.defectConfidence = defectDict.getDefectConfidence();
        }
        
        @Id
        @Column( name = "DEFECT_NAME", unique = true, nullable = false, length = 50 )
        public String getDefectName() {
                return defectName;
        }
        
        public void setDefectName( String defectName ) {
                this.defectName = defectName;
        }
        
        @Transient
        public double getDefectConfidence() {
                return this.defectConfidence;
        }
        
        public void setDefectConfidence( double defectConfidence ) {
                this.defectConfidence = defectConfidence;
        }
        
        public int compareTo(DefectDict defect) {
                return Double.compare(defectConfidence, defect.getDefectConfidence());
        }
        
        public String toString() {
                String defect = "<defect_name>" + this.getDefectName() + "</defect_name>";
                defect += "<defect_confidence>" + this.getDefectConfidence() + "</defect_confidence>";
                return defect;
        }
}
